package com.xin.entity;

import com.xin.enums.ResponseEnums;

public class CommonResult<T> {

    private T data;

    private String msg;

    private Integer code;
    public static CommonResult success(Object data){
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(ResponseEnums.SUCCESS.getCode());
        commonResult.setMsg(ResponseEnums.SUCCESS.getMsg());
        commonResult.setData(data);
        return commonResult;
    }
    public static CommonResult success(){
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(ResponseEnums.SUCCESS.getCode());
        commonResult.setMsg(ResponseEnums.SUCCESS.getMsg());
        return commonResult;
    }
    public static CommonResult error(ResponseEnums responseEnums){
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(responseEnums.getCode());
        commonResult.setMsg(responseEnums.getMsg());
        return commonResult;
    }
    public static CommonResult error(){
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(ResponseEnums.SUCCESS.getCode());
        commonResult.setMsg(ResponseEnums.SUCCESS.getMsg());
        return commonResult;
    }
    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String toString() {
        return "CommonResult{" +
                "data=" + data +
                ", msg='" + msg + '\'' +
                ", code=" + code +
                '}';
    }
}
